<!DOCTYPE html>
<html lang="ch-CN">
<head>
    <meta charset="UTF-8">
    <title>Date-时间对象</title>
</head>
<style>
    body {
        width: 100%;
        height: 100vh;
        background-color: wheat;
        font-size: 30px;
        text-decoration: none;
        font-family: "华文楷体";
    }

    p {
        font-size: 40px;
        margin: 20px 0 0 0;
        font-weight: bold;
    }

    span {
        display: block;
        line-height: 50px;
    }
    a{
        color: fuchsia;
        text-decoration: none;
    }
    a:hover{
        color: skyblue;
    }
</style>
<body>
<p><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date#%E6%96%B9%E6%B3%95">具体内容(点击我)</a></p>
</body>
<script>
    //start_time-开始的时间
    let start_time = Date.now()
    //打印系统的时间
    document.write("<p>获取的系统时间:</p>")
    {
        //创建一个Date对象
        let date = new Date()
        //打印的是当前代码执行的时间
        document.write("<span>" + date + "</span>")

        //获取当前日期多少号(1-31)
        let getDate = date.getDate()
        document.write("<span>今天是：" + getDate + "号</span>")

        //获取当前星期几(0-6)
        let getDay = date.getDay()
        document.write("<span>今天是周：" + getDay + "</span>")

        //获取月份(0-11)
        let getMonth = date.getMonth()
        document.write("<span>今天是：" + (getMonth + 1) + "月</span>")

        //获取年份
        let getFullYear = date.getFullYear()
        document.write("<span>今年是：" + getFullYear + "年</span>")

        //获取小时(0-23)
        let getHours = date.getHours()
        document.write("<span>现在已经：" + getHours + "点了</span>")

        /*
                *  getMinutes--获取Date对象的分钟(0-59)
                *  getSeconds--获取Date对象的秒数(0-59)
                *  getMilliseconds--获取Date对象的毫秒(0-999)
        */
    }
    //打印自定义的时间
    document.write("<p>获取的自定义时间:</p>")
    {
        let date = new Date("11/28/2022 17:12:55")
        document.write("<span>" + date + "</span>")

        //获取当前日期多少号(1-31)
        let getDate = date.getDate()
        document.write("<span>今天是：" + getDate + "号</span>")

        //获取当前星期几(0-6)
        let getDay = date.getDay()
        document.write("<span>今天是周：" + getDay + "</span>")

        //获取月份(0-11)
        let getMonth = date.getMonth()
        document.write("<span>今天是：" + (getMonth + 1) + "</span>")

        //获取年份
        let getFullYear = date.getFullYear()
        document.write("<span>今年是：" + getFullYear + "年</span>")

        //获取小时(0-23)
        let getHours = date.getHours()
        document.write("<span>现在已经：" + getHours + "点了</span>")
    }

    //end_time-结束的时间
    let end_time = Date.now()

    //用来查看代码执行所需要的时间
    let need_time = start_time - end_time
    //使用Math的abs方法取绝对值
    document.write("<br>代码执行所需要的时间:" + Math.abs(need_time)+"秒")
</script>
</html>